package com.test.daily.leetcode.y2022.m01.day0108;

import java.util.ArrayList;
import java.util.List;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/1/8 上午 09:11
 * @version: 1.0
 */
public class Code01_GrayCode {
    public List<Integer> grayCode1(int n) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(0);
        for(int i =1; i <= n; i++){
            int size = list.size();
            for(int j = size - 1; j >= 0; j--){
                list.add(list.get(j)|(1<<(i-1)));
            }
        }
        return list;
    }
    public List<Integer> grayCode2(int n) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        for(int i = 0; i < (1<<n); i++){
            list.add(i ^ (i >> 1));
        }
        return list;
    }
}
